import fetch from 'common/src/utils/fetch';

/**
 * 添加课程
 */
export function addCourse(data) {
  return fetch({
    url: '/api/cultureservice/courses',
    method: 'post',
    data
  });
}
/**
 * 修改课程
 */
export function editCourse(data) {
  return fetch({
    url: '/api/cultureservice/courses',
    method: 'put',
    data
  });
}
/**
 * 删除课程
 */
export function deleteCourse(data) {
  return fetch({
    url: '/api/cultureservice/courses',
    method: 'DELETE',
    data
  });
}
/**
 * 根据id查询课程详情
 */
export function getCourseById(id) {
  return fetch({
    url: '/api/cultureservice/courses/' + id,
    method: 'GET'
  });
}
/**
 * 根据code查询课程详情
 */
export function getCourseByCode(code) {
  return fetch({
    url: '/api/cultureservice/courses/' + code,
    method: 'GET'
  });
}
/**
 * 生成excel
 */
export function generateExcel(params) {
  // let query = '?';
  // for (let key in params) {
  //     query += key;
  //     query += '=';
  //     query += params[key];
  //     query += '&';
  // }
  return fetch({
    url: '/api/cultureservice/courses/exportExcel',
    method: 'post',
    data: params,
    showMask: false
  });
}

/**
 * 生成PDF
 */
export function generatePDF(params) {
  return fetch({
    url: '/api/cultureservice/courses/exportPdf',
    method: 'post',
    data: params,
    showMask: false
  });
}

/**
 * 生成word
 */
export function generateWord(params) {
  return fetch({
    url: '/api/cultureservice/courses/exportWord',
    method: 'post',
    data: params,
    showMask: false
  });
}

/**
 * 获取excel下载目录
 */
export function getCoursesReportStatus(key) {
  return fetch({
    url: '/api/cultureservice/courses/result/' + key,
    method: 'get'
  });
}

/**
 * 下载
 */
export function getExcelPath(path) {
  let url = '/api/cultureservice/courses/export?path=' + path;
  return url;
}

/**
 * 查询课程与第一外国语
 */
export function findCourseLanguage(params) {
  let url = '/api/cultureservice/firstLanguageContrast/page';
  let query = '?';
  for (let key in params) {
    query += key;
    query += '=';
    query += params[key];
    query += '&';
  }
  url += query;
  return fetch({
    url: url,
    method: 'GET'
  });
}

/**
 *
 * {添加第一外国语}
 */
export function addFirstLanguage(data) {
  return fetch({
    url: '/api/cultureservice/firstLanguageContrast',
    method: 'POST',
    data
  });
}
/**
 *
 * {删除第一外国语}
 */
export function deleteFirstLanguage(data) {
  return fetch({
    url: '/api/cultureservice/firstLanguageContrast',
    method: 'DELETE',
    data
  });
}
/**
 *  {查询第一外国语byId}
 */
export function findFirstLanguageById(id) {
  return fetch({
    url: '/api/cultureservice/firstLanguageContrast/' + id,
    method: 'GET'
  });
}
/**
 *  {修改第一外国语}
 */
export function updateFirstLanguageById(data) {
  return fetch({
    url: '/api/cultureservice/firstLanguageContrast',
    method: 'PUT',
    data
  });
}
/**
 *  {修改课程状态}
 */
export function updateCourseStatus(data) {
  return fetch({
    url: '/api/cultureservice/courses/status',
    method: 'PUT',
    data
  });
}

/**
 *  {课程审批单个}
 */
export function apporoveCourse(id, files) {
  return fetch({
    url: '/api/cultureservice/courses/apporove/',
    method: 'POST',
    data: {
      id: id,
      evidenceList: files
    }
  });
}
/**
 *  查看课程名是否使用
 */
export function checkCourseName(name, id) {
  let url = '/api/cultureservice/courses/name';
  let data = {};
  data.name = name;
  data.id = id;
  return fetch({
    url,
    method: 'POST',
    data: data
  });
}
/**
 * 根据id判断课程是否已重复
 */
export function checkCourseById(id) {
  return fetch({
    url: '/api/cultureservice/courses/check/' + id,
    method: 'GET'
  });
}

/**
 * 根据学院获取学科专业委员会列表
 * @param {学院Code} deptCode 
 * @returns 
 */
export function getSubjectMajorCommitteeByDept(deptCode) {
  return fetch({
    url: '/api/cultureservice/courses/getSubjectMajorCommitteeByDept/' + deptCode,
    method: 'GET'
  });
}
/**
 * 根据委员会code获取用户列表 * 
 * @param {委员会code}} committee 
 * @returns 
 */
 export function getSubjectMajorRoleByCommittee(committee) {
  return fetch({
    url: '/api/cultureservice/courses/getSubjectMajorRoleByCommittee/' + committee,
    method: 'GET'
  });
}

/**
 *  增加全国学位学科专业目录
 */
export function addMajor(data) {
  return fetch({
    url: '/api/baseresservice/nationalMajor',
    method: 'POST',
    data
  });
}

/**
 *  全国学位学科专业目录(分页)
 */
export function getMajorList(data) {
  return fetch({
    url: '/api/baseresservice/nationalMajor/page',
    method: 'POST',
    data
  });
}
/**
 *  全国学位学科专业目录(不分页)
 */
export function getAllMajorList(data) {
  return fetch({
    url: '/api/baseresservice/nationalMajor/list',
    method: 'POST',
    data
  });
}

/**
 *  根据id查询全国学位学科专业目录详情
 */
export function getMajorById(id) {
  return fetch({
    url: '/api/baseresservice/nationalMajor/' + id,
    method: 'GET'
  });
}

/**
 *  编辑全国学位学科专业目录
 */
export function editMajor(data) {
  return fetch({
    url: '/api/baseresservice/nationalMajor',
    method: 'PUT',
    data
  });
}
/**
 *  删除全国学位学科专业目录（包含批量删除）
 */
export function deleteMajor(data) {
  return fetch({
    url: '/api/baseresservice/nationalMajor',
    method: 'DELETE',
    data
  });
}
/**
 *  增加研究生学位学科目录(科学学位)
 */
export function addGraduateDegree(data) {
  return fetch({
    url: '/api/baseresservice/graduateDegree',
    method: 'POST',
    data
  });
}
/**
 * 根据条件，分页(不分页)查询研究生学位学科目录(科学学位)
 */
export function getGraduateDegreePage(data) {
  // 学位类型关联专业特殊处理
  if (data['type'] && data['type'] == 3) {
    data['type'] = '';
  }
  return fetch({
    url: '/api/baseresservice/graduateDegree/list',
    method: 'POST',
    data
  });
}
/**
 * 根据id查询研究生学位学科目录(科学学位)详情
 */
export function getGraduateDegreeById(id) {
  return fetch({
    url: '/api/baseresservice/graduateDegree/' + id,
    method: 'GET'
  });
}
/**
 *删除研究生学位学科目录(科学学位)（包含批量删除）
 */
export function deleteGraduateDegree(data) {
  return fetch({
    url: '/api/baseresservice/graduateDegree',
    method: 'DELETE',
    data
  });
}
/**
 *编辑研究生学位学科目录(科学学位)
 */
export function editGraduateDegree(data) {
  return fetch({
    url: '/api/baseresservice/graduateDegree',
    method: 'PUT',
    data
  });
}
/**
 *增加学位下的学生类别、院系关系管理
 */
export function addStudentCollege(data) {
  return fetch({
    url: '/api/baseresservice/studentCollege',
    method: 'POST',
    data
  });
}
/**
 *根据条件，分页(不分页)查询学位下的学生类别、院系关系
 */
export function getStudentCollegeList(data) {
  return fetch({
    url: '/api/baseresservice/studentCollege/list',
    method: 'POST',
    data
  });
}
/**
 *根据id查询学位下的学生类别、院系关系详情
 */
export function getStudentCollegeById(id) {
  return fetch({
    url: '/api/baseresservice/studentCollege/' + id,
    method: 'GET'
  });
}
/**
 *删除学位下的学生类别、院系关系管理（包含批量删除）
 */
export function deleteStudentCollegeById(data) {
  return fetch({
    url: '/api/baseresservice/studentCollege',
    method: 'DELETE',
    data
  });
}
/**
 *编辑学位下的学生类别、院系关系管理
 */
export function editStudentCollegeById(data) {
  return fetch({
    url: '/api/baseresservice/studentCollege',
    method: 'PUT',
    data
  });
}

/**
 *导出专业
 */
export function exportDegree(data) {
  let url = '/api/baseresservice/graduateDegree/exportExcel';
  downloadFile(data, url, 'major.xls');
}

function downloadFile(data, url, fileName) {
  fetch({
    url: url,
    method: 'POST',
    data,
    responseType: 'blob'
  }).then(resp => {
    if (!resp) {
      return;
    }
    let url = window.URL.createObjectURL(new Blob([resp]));
    let link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', fileName);
    document.body.appendChild(link);
    link.click();
  });
}

/**
 * 导出全国学科专业目录查询
 * @param {*} params
 */
export function exportMajor(data) {
  return fetch({
    url: 'api/baseresservice/nationalMajor/exportList',
    method: 'post',
    data,
    showMask: false
  });
}
/**
 * 全国学科专业目录查询导出状态查询
 * @param {*} params
 */
export function getReportStatus(key) {
  return fetch({
    url: 'api/baseresservice/nationalMajor/result/' + key,
    method: 'get'
  });
}

// 获取下载地址
export function getDownloadUrl() {
  return 'api/cultureservice/courses/template/import';
}

/**
 * 获取符合条件的开课学院
 */
export function getFacultys(isGraduate) {
  let data = {};
  data.isCourse = 1;
  data.currentState = 1;
  if (isGraduate) {
    data.isPostStudent = 1;
  } else {
    data.isUnderStudent = 1;
  }
  return fetch({
    url: '/api/userservice/dept/list',
    method: 'post',
    data: data
  });
}

export const downloadUrl =
  '/api/baseresservice/nationalMajor/downloadMaintenanceSubjectsTemplate';

/**
 * 研究生专业异步导入
 * @param {*} params
 */
export function getimportStatus(key) {
  return fetch({
    url: 'api/baseresservice/nationalMajor/import/' + key,
    method: 'get'
  });
}

export function getCoursePermission() {
  return fetch({
    url: '/api/cultureservice/courses/permission',
    method: 'get'
  })
}
export function updateCoursePermission(data) {
  return fetch({
    url: '/api/cultureservice/courses/updatePermission',
    method: 'post',
    data: data
  })
}
/**
 * 课程维护_编辑时间权限设置_新增
 * @param {*} data 
 */
export function addCourseTimeSetting(data) {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/add',
    method: 'post',
    data
  })
}
/**
 * 课程维护_编辑时间权限设置_编辑
 * @param {*} data 
 */
export function updateCourseTimeSetting(data) {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/update',
    method: 'put',
    data
  })
}
/**
 * 课程维护_编辑时间权限设置_删除
 * @param {*} data 
 */
export function deleteCourseTimeSetting(data) {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/delete',
    method: 'delete',
    data
  })
}
/**
 * 课程维护_编辑时间权限设置_获取详情
 * @param {*} data 
 */
export function getDetailCourseTimeSetting(id) {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/getDetail?id=' + id
  })
}
/**
 * 课程维护_编辑时间权限设置_查询列表（分页/不分页)
 * @param {*} data 
 */
export function queryCourseTimeSetting(data) {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/query',
    method: 'post',
    data
  })
}

/**
 * 获取当前用户管理学院的课程维护时间
 * @param {*} data 
 */
export function queryListByCurrentUser() {
  return fetch({
    url: '/api/cultureservice/courseMaintenanceTimeSetting/queryListByCurrentUser',
    method: 'post'    
  })
}


export const downloadSubjectUrl = 'api/baseresservice/nationalMajor/downloadMaintenanceSubjectsTemplate';
export const downloadFristUrl = 'api/baseresservice/nationalMajor/downloadFirstLevelDisciplinesTemplate';
export const downloadSecondUrl = 'api/baseresservice/nationalMajor/downloadSecondaryDisciplinesTemplate';
export const downloadDegreeUrl = 'api/baseresservice/nationalMajor/downloadProfessionalDegreeTemplate';
export const downloadDomainUrl = 'api/baseresservice/nationalMajor/downloadProfessionalDomainTemplate';
